package cn.yunhe.controller;

import cn.yunhe.model.User;
import cn.yunhe.service.IUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述
 * @创建人 李辉
 * @创建时间 2017/12/22
 * @修改人和其它信息
 */
@Controller
@RequestMapping("/getpage")
public class UserRestAction {
    @Resource(name = "userService")
    private IUserService userService;
    @RequestMapping("/pagesssm")
    public ModelAndView userpage(@RequestParam int pageNum,@RequestParam int pageSize,@RequestParam String name){
        ModelAndView mv = new ModelAndView();
        Map<String,Object> map = new HashMap<String, Object>();
        User us = new User();
        us.setName(name);
        map.put("user",us);
        int count = userService.getLikeUsersCount(map);
        Page page = new Page();
        page.setPageSize(pageSize);
        page.setTotal(count);
        page=PageHelper.startPage(pageNum,pageSize);
        List<User> list = userService.getLikeUsers(map);

        mv.addObject("total",page.getTotal());
        mv.addObject("pages",page.getPages());
        mv.addObject("page",page);
        mv.setView(new MappingJackson2JsonView());
       // mv.addObject("list",list);
        //mv.setViewName("index");
        return mv;
    }
    @RequestMapping("/go")
    public ModelAndView golist(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("list");
        return mv;
    }

    public IUserService getUserService() {
        return userService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }
}
